package subject.homework.zoosystrem.father;
import subject.homework.zoosystrem.sons1.*;
import subject.homework.zoosystrem.serve.*;
import java.util.ArrayList;
import java.util.List;

public class UserCollections implements IUserDataAccess,IDisplayInformation{


    //private UserAdmin parkCorrespondingAdmin; //园区管理员

    protected List<UserAnimal> userList;     //园区内动物
    protected List<UserAdmin> AdminList;     //园区内动物
    private Integer animalTypeNum=0;     //动物种类数


    //private List<UserAnimal> classStudentList;

    //方法重写
    public UserCollections() {
        userList = new ArrayList<>();
        AdminList = new ArrayList<>();
    }
    public UserCollections(List<UserAnimal> animalList){
        this.userList = animalList;
    }
    public UserCollections(List<UserAnimal> animalList,List<UserAdmin> adminList){
        this.userList = animalList;
        this.AdminList = adminList;
        this.userList = new ArrayList<UserAnimal>();
    }

    //获取动物种类数
    public Integer getAnimalTypeNum() {
        return animalTypeNum;
    }
    public void setAnimalTypeNum(Integer animalTypeNum) {
        this.animalTypeNum = animalTypeNum;
    }

    @Override
    public boolean addUser(UserAnimal animal) {
        this.animalTypeNum++;//在列表里增加用户
        return this.userList.add(animal);
    }

    @Override
    public boolean addAdmin(UserAdmin admin) {
        return this.AdminList.add(admin);
    }

    @Override
    public boolean deleteUser(UserAnimal user) {
        this.animalTypeNum--;//在列表里删除传入的用户对象,
        return this.userList.remove(user);
    }

    @Override
    public boolean deleteAdmin(UserAdmin admin) {
        return this.AdminList.remove(admin);
    }


    @Override
    public boolean deleteUser(String userName) {
        this.animalTypeNum--;//在列表里删除传入的用户名对应的对象
        return deleteUser(findUser(userName));
    }

    @Override
    public boolean deleteAdmin(String adminName) {
        return deleteUser(findUser(adminName));
    }


    @Override
    public boolean updateUser(UserAnimal oldUser, UserAnimal newUser) {
        boolean updateUserSucessed = false;
        if (oldUser == findUser(oldUser.getUserName())){
            if (deleteUser(oldUser)) {
                updateUserSucessed = addUser(newUser);
            }
        }
        return updateUserSucessed;
    }

    @Override
    public UserAnimal findUser(String userName) {
        UserAnimal foundUser = null;
        for (UserAnimal current : this.userList){
            if (current.getUserName().equals(userName)){
                foundUser = current;
            }
        }
        return foundUser;
    }

    @Override
    public User findAdmin(String adminName) {
        UserAdmin foundUser = null;
        for (UserAdmin current : this.AdminList){
            if (current.getUserName().equals(adminName)){
                foundUser = current;
            }
        }
        return foundUser;
    }

    @Override
    public String displayAllAnimals() {
        //String displayMessageString = "";
        for(User currentUser:this.userList){
            System.out.println(currentUser.getUserName());
            System.out.println("\n");
            //displayMessageString +=currentUser.getUserName();
        }
        //return displayMessageString;
        return null;
    }
}
